package com.hmall.search.config;

import com.hmall.search.constant.MqConstants;
import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class MqConfiguration {

    /**
     * 交换机
     *
     * @return {@link TopicExchange}
     */
    @Bean
    public TopicExchange hmallTopicExchange(){
        return ExchangeBuilder.topicExchange(MqConstants.HMALL_EXCHANGE).build();
    }

    /**
     * 新增或修改队列
     *
     * @return {@link Queue}
     */
    @Bean
    public Queue hmallInsertAndUpdateQueue(){
        return QueueBuilder.durable(MqConstants.HMALL_INSERT_QUEUE).build();
    }
    /**
     * 删除队列
     *
     * @return {@link Queue}
     */
    @Bean
    public Queue hmallDeleteQueue(){
        return QueueBuilder.durable(MqConstants.HMALL_DELETE_QUEUE).build();
    }

    /**
     * 新增或修改队列 与 交换机 的绑定
     *
     * @return {@link Binding}
     */
    @Bean
    public Binding hotelInsertQueueBindingHotelTopicExchange(){
        return BindingBuilder.bind(hmallInsertAndUpdateQueue())
                .to(hmallTopicExchange())
                .with(MqConstants.HMALL_INSERT_KEY);
    }

    /**
     * 新增或修改队列 与 交换机 的绑定
     *
     * @return {@link Binding}
     */
    @Bean
    public Binding hotelDeleteQueueBindingHotelTopicExchange(){
        return BindingBuilder.bind(hmallDeleteQueue())
                .to(hmallTopicExchange())
                .with(MqConstants.HMALL_DELETE_KEY);
    }
}
